home *** CD-ROM | disk | FTP | other *** search
Wrap
# v 0.6 import BP, cPickle ak = ["akLeft", "akBottom"] ck = "TCheckBox" cb = "TComboBox" bt = "TButton" fh = "Ex: ½ cinΘma ╗ ou ½ =details[:10] ╗\n\nVariables disponibles :\ndate, mode, tiers, details et montant" no = "- InchangΘ -" none = "- Aucune -" i = BP.AccountCurrent() ODat = BP.OperationDate[i] OMod = BP.OperationMode[i] OWho = BP.Operationthirdparty[i] OInf = BP.OperationDetails[i] OAmt = BP.OperationAmount[i] OCtg = BP.OperationCateg[i] CPrt = BP.CategParent sl = SingleLine() fields = ["Tiers", "DΘtails", "Tiers ou DΘtails"] str_modes = [BP.OperationGetNameFromModeIndex(i) for i in range(10)] cnames = BP.CategName CTrimNames = [] CPositions = {-1: -1} CIndexes = {-1: -1} CNames = [] for i, c in enumerate(cnames): p = c.find("=") CNames.append(c[p+1:]) CTrimNames.append(c[p+1:].strip()) idx = int(c[:p]) CPositions[idx] = i CIndexes[i] = idx ic = "\n".join([none] + CNames) cc = [none] + [ ("%s > %s" %(CTrimNames[CPrt[i]], c), c)[CPrt[i] == i] for i, c in enumerate(CTrimNames)] def EditRule(l): CBField.ItemIndex = l["field"] EVal.Text = l["contains"] CkMod.Checked = l["do_mode"] CBMod.ItemIndex = l["mode"] ChkWho.Checked = l["do_third"] EWho.Text = l["third"] CkInf.Checked = l["do_info"] EInfo.Text = l["info"] CkCtg.Checked = l["do_categ"] CBCtg.Items.Text = ic CBCtg.ItemIndex = CPositions[l["categ"]] + 1 CkAct.Checked = l["active"] CkAuto.Checked = l.get("withnewline", 0) if F1.ShowModal() == 1 and EVal.Text != "": return {"field": CBField.ItemIndex, "contains": EVal.Text, "do_mode": CkMod.Checked, "mode": CBMod.ItemIndex, "do_third": ChkWho.Checked, "third": EWho.Text, "do_info": CkInf.Checked, "info": EInfo.Text, "do_categ": CkCtg.Checked, "categ": CIndexes[CBCtg.ItemIndex - 1], "active": CkAct.Checked, "withnewline": CkAuto.Checked} else: return None def ApplyAll(S): T = 0 for line in file_lines: if line["active"]: T += ApplyRule(line, BP.VisibleLines(), 1) BP.AccountRefreshScreen() if T == 0: s = "Aucune ligne n'a ΘtΘ modifiΘe" elif T == 1: s = "Une seule ligne a ΘtΘ modifiΘe" else: s = "%d lignes ont ΘtΘ modifiΘes" %T BP.MsgBox(s, 64) def ModifLine(S): i = Grid.Selection.Top - 1 if i == -1: return l = file_lines[i] res = EditRule(l) if not res is None: file_lines[i] = res SaveFile() def Enable(S): i = Grid.Selection.Top - 1 if i == -1: return l = file_lines[i] l["active"] = not l["active"] SaveFile() def Delete(S): i = Grid.Selection.Top - 1 if i == -1: return l = file_lines[i] if BP.MsgBox("Voulez-vous vraiment supprimer cette rΦgle ?", 36) == 6: del file_lines[i] SaveFile() def Apply(S): i = Grid.Selection.Top - 1 if i == -1: return l = file_lines[i] ApplyRule(l, BP.VisibleLines()) BP.AccountRefreshScreen() def draw(Sender, ACol, ARow, R, State): cv = Sender.Canvas if "gdSelected" in State: cv.Brush.Color = 0x00dec5b9 elif ARow > 0 and ARow % 2 == 0: cv.Brush.Color = 0x00f0f0f0 cv.FillRect(R) try: if ARow == 0: s = ["Si je trouve", "Dans le champ", "J'affecte le mode", "Le tiers", "Le dΘtail", "La catΘgorie"][ACol] cv.Font.Style = ["fsBold"] else: s = code[ARow - 1][ACol] except: s = "" if ACol == 1 and ARow > 0 and code[ARow - 1][0].startswith("="): s = "" if s.startswith("="): cv.Font.Color, s = 0x00CC0000, s[1:] elif s in [no, none]: cv.Font.Color = 0x00666666 else: cv.Font.Color = 0x00000000 if ACol == 0: R.Left = R.Left + 14 if s != "": cv.TextRect(R, R.Left + 3, R.Top + 5, s) if ACol == 0 and ARow > 0: y = (R.Bottom - R.Top) / 2 R.Left, R.Right, R.Top, R.Bottom = R.Left - 12, R.Left + - 2, R.Top + y - 5, R.Top + y + 5 cv.Brush.Color = 0x00000000 cv.FillRect(R) R.Left, R.Right, R.Top, R.Bottom = R.Left + 1, R.Right - 1, R.Top + 1, R.Bottom - 1 if code[ARow - 1][6]: cv.Brush.Color = 0x0000AA00 else: cv.Brush.Color = 0x000000CC cv.FillRect(R) cv.Brush.Style = 1 def Resize(S): Grid.DefaultColWidth = (Grid.Width - 40) / 6 def AddLine(S): line = {"field": 0, "contains": "", "do_mode": 0, "mode": 0, "do_third": 0, "third": "", "do_info": 0, "info": "", "do_categ": 0, "categ": -1, "active": 0, "withnewline": 0} res = EditRule(line) if not res is None: file_lines.append(res) SaveFile() F0 = CreateComponent("TForm", None) F0.SetProps(Position="poMainFormCenter", Width=770, Height=340, Caption="Calcul automatique des champs", OnResize=Resize) F0.Constraints.MinWidth = 700 F0.Constraints.MinHeight = 340 F0.Font.Name = "Tahoma" Grid = CreateComponent("TDrawGrid", F0) Grid.SetProps(Parent=F0, Top=30, Left=30, Width=710, Height=243, Anchors=ak+["akTop", "akRight"], ColCount=6, FixedCols=0, OnDrawCell=draw, Options = ["goFixedHorzLine", "goVertLine", "goDrawFocusSelected", "goRowSelect", "goThumbTracking"], Hint="Double-cliquez sur une ligne pour l'activer ou la dΘsactiver", ShowHint=1, OnDblClick=Enable) BAdd = CreateComponent(bt, F0) BAdd.SetProps(Parent=F0, Left=30, Top=293, Width=90, Height=25, Anchors=ak, Caption="Ajouter", OnClick=AddLine) BChg = CreateComponent(bt, F0) BChg.SetProps(Parent=F0, Left=130, Top=293, Width=90, Height=25, Anchors=ak, Caption="Modifier", OnClick=ModifLine) BDel = CreateComponent(bt, F0) BDel.SetProps(Parent=F0, Left=226, Top=293, Width=90, Height=25, Anchors=ak, Caption="Supprimer", OnClick=Delete) BApp = CreateComponent(bt, F0) BApp.SetProps(Parent=F0, Left=324, Top=293, Width=90, Height=25, Anchors=ak, Caption="Appliquer", OnClick=Apply) BAppAll = CreateComponent(bt, F0) BAppAll.SetProps(Parent=F0, Left=422, Top=293, Width=90, Height=25, Anchors=ak, Caption="Appliquer actives", OnClick=ApplyAll) BQuit = CreateComponent(bt, F0) BQuit.SetProps(Parent=F0, Left=522, Top=293, Width=90, Height=25, Anchors=ak, Caption="Fermer", Cancel=1, Default=1, ModalResult=1) F1 = CreateComponent("TForm", None) F1.SetProps(Width=430, Height=380, Caption="Correspondance", Position="poMainFormCenter", BorderStyle="bsSingle", BorderIcons=["biSystemMenu"]) L0 = CreateComponent("TLabel", F1) L0.SetProps(Parent=F1, Left=30, Top=25, Width=60, Caption="Si le champ :") L1 = CreateComponent("TLabel", F1) L1.SetProps(Parent=F1, Left=30, Top=53, Width=92, Caption="Contient la valeur :") CBField = CreateComponent(cb, F1) CBField.SetProps(Parent=F1, Left=196, Top=20, Width=200, Style="csDropDownList") CBField.Items.Text = "\n".join(fields) EVal = CreateComponent("TEdit", F1) EVal.SetProps(Parent=F1, Left=196, Top=48, Width=200, Hint="Ex: ½ cinΘma ╗ ou ½ salaire+!chantal ╗", ShowHint=1) CkMod = CreateComponent(ck, F1) CkMod.SetProps(Parent=F1, Left=30, Top=89, Width=134, Caption="J'applique le mode :") CBMod = CreateComponent(cb, F1) CBMod.SetProps(Parent=F1, Left=196, Top=86, Width=200, Style="csDropDownList") CBMod.Items.Text = "\n".join(str_modes) ChkWho = CreateComponent(ck, F1) ChkWho.SetProps(Parent=F1, Left=30, Top=126, Width=160, Caption="J'applique le tiers :") EWho = CreateComponent("TEdit", F1) EWho.SetProps(Parent=F1, Left=196, Top=124, Width=200, Hint=fh, ShowHint=1) CkInf = CreateComponent(ck, F1) CkInf.SetProps(Parent=F1, Left=30, Top=164, Width=160, Caption="J'applique le dΘtail :") EInfo = CreateComponent("TEdit", F1) EInfo.SetProps(Parent=F1, Left=196, Top=162, Width=200, Hint=fh, ShowHint=1) CkCtg = CreateComponent(ck, F1) CkCtg.SetProps(Parent=F1, Left=30, Top=203, Width=134, Caption="J'applique la catΘgorie :") CBCtg = CreateComponent(cb, F1) CBCtg.SetProps(Parent=F1, Left=196, Top=200, Width=200, Style="csDropDownList") CkAct = CreateComponent(ck, F1) CkAct.SetProps(Parent=F1, Left=30, Top=240, Width=300, Caption="Activer la rΦgle") CkAuto = CreateComponent(ck, F1) CkAuto.SetProps(Parent=F1, Left=30, Top=260, Width=300, Caption="Appliquer automatiquement α chaque nouvelle ligne") BOK = CreateComponent(bt, F1) BOK.SetProps(Parent=F1, Left=110, Top=300, Width=90, Height=25, Caption="OK", Default=1, ModalResult=1) BCnl = CreateComponent(bt, F1) BCnl.SetProps(Parent=F1, Left=210, Top=300, Width=90, Height=25, Caption="Annuler", Cancel=1, ModalResult=2) exe_path = BP.BankPerfectExePath() file_name = BP.BankPerfectFileName() file_name = file_name[file_name.rfind("\\") + 1:-3] file_path = exe_path + "Scripts\\Auto Fields\\%s.dat" %file_name def SaveFile(): f = open(file_path, "w") cPickle.dump(file_lines, f) f.close() global code code = FillGrid(file_lines) i = Grid.Selection.Top C = len(file_lines) Grid.RowCount = C + 1 Grid.Repaint() if i > 0 and i <= C: Grid.Row = i def LoadFile(): global file_lines try: f = open(file_path, "r") file_lines = cPickle.load(f) f.close() except: file_lines = [] def ApplyRule(line, AccountLines, silent = 0): field = line["field"] lfield = fields[field].lower() if not silent and line["do_categ"] and not (line["categ"] in CPositions.keys()): BP.MsgBox("La catΘgorie α appliquer n'existe pas", 64) return ops = [] i = 0 val = line["contains"] if val[0] == "=": ask, val, formula = "formule", val[1:], 1 else: ask, formula = "rΦgle", 0 for i in AccountLines: simple = 1 if formula: date, mode, tiers, details, montant = ODat[i], OMod[i], OWho[i], OInf[i], OAmt[i] try: if eval(val): ops.append(i) simple = 0 except: pass if simple: if field == 0: op = OWho[i] elif field == 1: op = OInf[i] elif field == 2: op = OWho[i] + " " + OInf[i] if MatchVal(op, val): ops.append(i) nb_lines = len(ops) if nb_lines > 0: if nb_lines == 1: s1, s2 = "une seule ligne qui vΘrifie la %s ½ %s ╗" %(ask, val), "la" else: s1, s2 = "%d lignes qui vΘrifient la %s ½ %s ╗" %(nb_lines, ask, val), "les" if sl == -1 and BP.MsgBox("Il y a %s.\n\nSouhaitez-vous %s modifier ?" %(s1, s2), 36) != 6: return 0 for i in ops: tiers, details, date, montant, mode = OWho[i], OInf[i], ODat[i], OAmt[i], OMod[i] if line["do_mode"]: m = line["mode"] v = OAmt[i] mode_value = str_modes[m] if (m <= 5 and v < 0) or (m >= 6 and v > 0): OMod[i] = mode_value if line["do_third"]: s = line["third"] if s <> "" and s[0] == "=": try: s = eval(s[1:]) except: pass OWho[i] = s if line["do_info"] : s = line["info"] if s <> "" and s[0] == "=": try: s = eval(s[1:]) except: pass OInf[i] = s if line["do_categ"]: OCtg[i] = line["categ"] elif not silent: BP.MsgBox("Aucune ligne rΘpondant aux critΦres n'a ΘtΘ trouvΘe", 0) return nb_lines def MatchVal(line, value): vals = value.split("+") for v in vals: if v == "": continue if v[0] == "!": must_find = 0 v = v[1:] else: must_find = 1 found = line.find(v) > -1 if must_find and not found: return 0 if not must_find and found: return 0 return 1 def FillGrid(file_lines): code = [] for l in file_lines: if l.get("do_mode", 0): idx = l["mode"] if idx >= len(str_modes): idx = 0 m = str_modes[idx] else: m = no if l.get("do_third", 0): t = l["third"] else: t = no if l.get("do_info", 0): i = l["info"] else: i = no if l.get("do_categ", 0): idx = CPositions[l["categ"]] + 1 if idx >= len(cc): idx = 0 c = cc[idx] else: c = no code.append([l["contains"], fields[l["field"]], m, t, i, c, l.get("active", 0)]) return code LoadFile() if sl > -1: for l in file_lines: if l.get("withnewline", 0): ApplyRule(l, [sl], 1) BP.AccountRefreshScreen() elif file_name != "": code = FillGrid(file_lines) Grid.RowCount = len(file_lines) + 1 F0.ShowModal()